package com.cloudlinkscm.base.authcenter.code;

import com.cloudlinkscm.loms.framework.core.pojo.ErrorCode;
import com.cloudlinkscm.loms.framework.core.pojo.ErrorMessage;
import com.cloudlinkscm.loms.framework.core.pojo.Language;

import java.util.HashMap;

/**
 * @author : tac
 * @date : 2017/7/29
 */
public enum AuthCenterErrorCode implements ErrorCode {
    INCORRECT_USER_ACCOUNT_OR_PASSWORD_EXCEPTION("201"),
    USER_ACCOUNT_IS_DISABLED_EXCEPTION("203"),
    USER_ACCOUNT_NOT_ACTIVE_EXCEPTION("204"),
    INCORRECT_PASSWORD_EXCEPTION("205"),
    ROLE_DELETE_EXCEPTION("206"),
    USER_ACCOUNT_NOT_FIND_EXCEPTION("207"),
    USER_ACCOUNT_IS_ACTIVE_EXCEPTION("208"),
    EXISTED_USERNAME_EXCEPTION("209"),
	USER_ACCOUNT_USER_NAME_EXISTED_EXCEPTION("210"),
	PUBLIC_RESOURCE_TYPE_INCORRECT_EXCEPTION("211"),
	PUBLIC_RESOURCE_KEY_REPEAT_EXCEPTION("212"),
	PUBLIC_RESOURCE_PARENT_NOT_FIND_EXCEPTION("213"),
	TENANT_RESOURCE_MOVE_NODE_NOT_FIND_EXCEPTION("214"),
	TENANT_RESOURCE_MOVE_NODE_ID_RESOURCE_NOT_FIND_EXCEPTION("215"),
	TENANT_RESOURCE_MOVE_TARGET_NODE_ID_NOT_FIND_EXCEPTION("216"),
	TENANT_RESOURCE_MOVE_OUT_NODE_NOT_FIND_EXCEPTION("217"),
	ROLE_NAME_REPEAT_EXCEPTION("218"),
	ROLE_NOT_FIND_EXCEPTION("219"),
	ROLE_RELATION_NOT_FIND_EXCEPTION("220"),
	ROLE_RELATION_IS_EXISTS_EXCEPTION("221"),
	USER_ACCOUNT_NO_CACHE_EXCEPTION("222"),

    ;

    private String code;
    AuthCenterErrorCode(String code) {
        this.code = code;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return errorMessage.getErrorMessage(this);
    }

    @Override
    public String getInternationalMessage(Language language) {
        return errorMessage.getInternationalErrorMessage(this, language);
    }

    @Override
    public String getInternationalMessage(Language language, Object... args){
        return errorMessage.getInternationalErrorMessage(this, language, args);
    }

    private static HashMap<ErrorCode, String> zh = new HashMap<>();
    private static HashMap<ErrorCode, String> en = new HashMap<>();

    static {
        zh.put(INCORRECT_USER_ACCOUNT_OR_PASSWORD_EXCEPTION, "用户账号或密码错误");
        zh.put(USER_ACCOUNT_IS_DISABLED_EXCEPTION, "用户账号被禁用");
        zh.put(USER_ACCOUNT_NOT_ACTIVE_EXCEPTION, "用户账号未激活");
        zh.put(INCORRECT_PASSWORD_EXCEPTION, "密码不正确");
        zh.put(ROLE_DELETE_EXCEPTION, "删除角色失败：%s");
        zh.put(USER_ACCOUNT_NOT_FIND_EXCEPTION, "用户未找到");
        zh.put(USER_ACCOUNT_IS_ACTIVE_EXCEPTION, "用户已激活");
        zh.put(EXISTED_USERNAME_EXCEPTION, "已存在的用户名：%s");
        zh.put(USER_ACCOUNT_USER_NAME_EXISTED_EXCEPTION, "用户名已存在");
        zh.put(PUBLIC_RESOURCE_TYPE_INCORRECT_EXCEPTION, "类型不正确");
        zh.put(PUBLIC_RESOURCE_KEY_REPEAT_EXCEPTION, "key重复");
        zh.put(PUBLIC_RESOURCE_PARENT_NOT_FIND_EXCEPTION, "父级没找到");
        zh.put(TENANT_RESOURCE_MOVE_NODE_NOT_FIND_EXCEPTION, "租户资源移动的节点未找到");
        zh.put(TENANT_RESOURCE_MOVE_NODE_ID_RESOURCE_NOT_FIND_EXCEPTION, "移动的资源未找到");
        zh.put(TENANT_RESOURCE_MOVE_TARGET_NODE_ID_NOT_FIND_EXCEPTION, "移动的目标节点没找到");
        zh.put(TENANT_RESOURCE_MOVE_OUT_NODE_NOT_FIND_EXCEPTION, "移出的节点未找到");
        zh.put(ROLE_NAME_REPEAT_EXCEPTION, "角色名称重复");
        zh.put(ROLE_NOT_FIND_EXCEPTION, "角色没有找到");
        zh.put(ROLE_RELATION_NOT_FIND_EXCEPTION, "角色关系id 没有找到");
        zh.put(ROLE_RELATION_IS_EXISTS_EXCEPTION, "角色关系 已存在");
        zh.put(USER_ACCOUNT_NO_CACHE_EXCEPTION, "用户账户没有缓存");
    }

    static {
        en.put(INCORRECT_USER_ACCOUNT_OR_PASSWORD_EXCEPTION, "incorrect user account or password");
        en.put(USER_ACCOUNT_IS_DISABLED_EXCEPTION, "user account is disabled");
        en.put(USER_ACCOUNT_NOT_ACTIVE_EXCEPTION, "incorrect user account or password");
        en.put(INCORRECT_PASSWORD_EXCEPTION, "incorrect password");
        en.put(ROLE_DELETE_EXCEPTION, "fail to delete role: %s");
        en.put(USER_ACCOUNT_NOT_FIND_EXCEPTION, "can not find account");
        en.put(USER_ACCOUNT_IS_ACTIVE_EXCEPTION, "this account is active now");
        en.put(EXISTED_USERNAME_EXCEPTION, "user name \"%s\" is existed");
        en.put(USER_ACCOUNT_USER_NAME_EXISTED_EXCEPTION, "user name is existed");
        en.put(PUBLIC_RESOURCE_TYPE_INCORRECT_EXCEPTION, "resource type incorrect");
        en.put(PUBLIC_RESOURCE_KEY_REPEAT_EXCEPTION, "resource key repeat");
        en.put(PUBLIC_RESOURCE_PARENT_NOT_FIND_EXCEPTION, "parent not find");
        en.put(TENANT_RESOURCE_MOVE_NODE_NOT_FIND_EXCEPTION, "move node not find");
        en.put(TENANT_RESOURCE_MOVE_TARGET_NODE_ID_NOT_FIND_EXCEPTION, "move target node id not find");
        en.put(TENANT_RESOURCE_MOVE_OUT_NODE_NOT_FIND_EXCEPTION, "move out node not find");
        en.put(ROLE_NAME_REPEAT_EXCEPTION, "role name repeat");
        en.put(ROLE_NOT_FIND_EXCEPTION, "role not find");
        en.put(ROLE_RELATION_NOT_FIND_EXCEPTION, "role relation not find");
        en.put(ROLE_RELATION_IS_EXISTS_EXCEPTION, "role relation is exists");
        en.put(USER_ACCOUNT_NO_CACHE_EXCEPTION, "user account no cache.");
    }

    private static ErrorMessage errorMessage = new ErrorMessage(zh, en);
}
